/**
 * Created by hzw on 2016/4/15.
 * connect 342782880
 * @params url 数据请求地址
 * @params keyName 数据返回的列表字段
 * @params datafilter 数据过滤函数，过程写在datafilter.js
 * @params headName,表格的标题栏
 * @params param,数据需要显示的字段
 */

import React from "react"
import ReactDOM from "react-dom"
var  DataFilter=require("../js/datafilter");
import UNIT from "../js/unit"
import Table from "./table"

module.exports={
    search:React.createClass({
        showContent:function(){
            if($("#searchForm").is(":visible")){
                $("#searchForm").hide();
            }else{
                $("#searchForm").show();
            }
        },
        render: function() {
            return (
                <button type="button" className="btn btn-default" onClick={this.showContent} >
                    <i className="fa fa-search">
                    </i>
                </button>
            );
        }
    }),
   InputBox:React.createClass({
        render: function() {
            return (
                <div className="form-group col-xs-3">
                    <label className="col-sm-4 control-label">{this.props.title}</label>
                    <div className="col-sm-8">
                        <input type="email" name={this.props.name} className="form-control" placeholder={this.props.title}/>
                    </div>
                </div>
            )
        }
    }),
     SelectBox:React.createClass({
        render: function() {
            return (
                <div className="form-group col-xs-3">
                    <label className="col-sm-4 control-label">{this.props.title}</label>
                    <div className="col-sm-8">
                        <select name={this.props.name} className="form-control">
                            <option value="1">1</option>
                            <option value="2">2</option>
                        </select>
                    </div>
                </div>
            )
        }
    }),
    TextareaBox:React.createClass({
        render: function() {
            return (
                <div className="form-group col-xs-6">
                    <label className="col-sm-4 control-label">{this.props.title}</label>
                    <div className="col-sm-8">
                    <textarea type="email" name={this.props.name} className="form-control" placeholder={this.props.title} >
                    </textarea>
                    </div>
                </div>
            )
        }
    }),
    submit:React.createClass({
        handlefn:function(e){
            e.preventDefault();
            var data=$(e.target).closest("form").serializeObject();
            if(this.props.searchTest){
                data=eval("DataFilter."+this.props.searchTest+"(data)");
            }
            console.log(this.props.url+"?"+data.toParams());
            ReactDOM.render(
               /* <Table
                    url={this.props.url+JSON.stringify(data)}
                    keyName={this.props.keyName}
                    headName={this.props.headName}
                    datafilter={this.props.datafilter}
                    params={this.props.params} />*/
                <Table
            url={UNIT.domain+"admin/blog/checklist/get.do"}
            keyName="bloglist"
            headName="序号,名称"
            datafilter="searchFilter"
            params="originid,originName"/>,
                document.getElementById('tableList')
            );

        },
        render: function() {
            return (
                <button type="submit" className="btn btn-info" onClick={this.handlefn}>查询</button>
            )
        }
    })
}
